/*
 * @Author       : wfl
 * @LastEditors  : wfl
 * @description  :
 * @updateInfo   :
 * @Date         : 2023-06-05 19:18:06
 * @LastEditTime : 2023-06-06 15:33:24
 */
export const computedLocalStorageSize = () => {
  // 获取所有localStorage键名
  const keys = Object.keys(localStorage)

  // 计算总大小（单位：字节）
  let totalSize = 0
  for (let i = 0; i < keys.length; i++) {
    const key = keys[i]
    const value = localStorage.getItem(key) || ''
    const size = (key.length + value.length) * 2 // 键名和键值都是字符串类型，每个字符占两个字节
    totalSize += size
  }
  const totalSizeInKB = Math.round(totalSize / 1024) // 将字节转换为KB并四舍五入
  console.info(`%c当前localStorage已使用 ${totalSizeInKB}KB 的容量`, 'color: green; font-weight: bold')
}
